<template>
	<view class="page">
		<view class="bar_info" :style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx'}">
			<view class="title_bar">
				<view class="title_bar_left" @tap.stop="handleJump" data-type="BACK">
					<image class="title_bar_left_icon" :src='STATIC_URL+"5.png"'></image>
				</view>
				<view class="title_bar_center">
					编辑地址
				</view>
				<view class="title_bar_right"></view>
			</view>
		</view>
		<view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
		<view class="loading_css" v-if="isShow">
			<u-loading size="36" color="#41AF36"></u-loading>
			<view class="loading_text">加载中</view>
		</view>
		<template v-else>
			<view class="set_content">
				<view class="set_list">
					<view class="list_item">
						<view class="list_item_left">收货人</view>
						<view class="list_item_right">
							<u-input v-model="userInfo.consignee" :clearable="false" placeholder="请输入收货人姓名" placeholder-style="color:#999;font-size: 26rpx;" type="text" maxlength="-1" input-align="right" height="42" />
						</view>
					</view>
					<view class="list_item">
						<view class="list_item_left">手机号</view>
						<view class="list_item_right">
							<u-input v-model="userInfo.tel" :clearable="false" placeholder="请输入收货人手机号" placeholder-style="color:#999;font-size: 26rpx;" type="number" maxlength="11" input-align="right" height="42" />
						</view>
					</view>
					<view class="list_item" @tap.stop="pickerDiy1656986153485=true">
						<view class="list_item_left">所在地区</view>
						<view class="list_item_right flex align-center" style="pointer-events: none;">
							<u-input v-model="address" :clearable="false" :disabled="true" placeholder="请选择省、市、区" placeholder-style="color:#999;font-size: 26rpx;" type="text" maxlength="-1" input-align="right" height="42" />
							<u-icon name="arrow-right" size="26" color="#999999"></u-icon>
						</view>
					</view>
					<view class="list_item no_border">
						<view class="list_item_left">详细地址</view>
						<view class="list_item_right">
							<u-input v-model="userInfo.receiving_address" :clearable="false" placeholder="请输入详细地址 例如小区/单元/楼层等" placeholder-style="color:#999;font-size: 26rpx;" type="text" maxlength="-1" input-align="right" height="42" />
						</view>
					</view>
				</view>
			</view>
			
			<view class="btn_info">
				<!-- <view class="del_btn">删除</view> -->
				<view class="save_btn" @tap.stop="saveInfo">保存</view>
			</view>
		</template>
		
		
		<benben-picker ref="benbenWritePickerCodepicker2" :visible.sync="pickerDiy1656986153485"
			:value.sync='area' mode='region' :picker-height='88' :current='true' :mask-show='true' :timeout='true' @change="areaChange">
			<template #picker-header>
				<view class='flex flex-wrap align-center justify-between myInfo_picker2_0'>
					<text class='myInfo_picker2_0_c0' @tap="$refs.benbenWritePickerCodepicker2.cancel()">取消</text>
					<text class='myInfo_picker2_0_c1'>选择地区</text>
					<text class='myInfo_picker2_0_c2'
						@tap="$refs.benbenWritePickerCodepicker2.pickerConfirm()">确定</text>
				</view>
			</template>
		</benben-picker>
	</view>
</template>

<script>
	import {
		validate
	} from '@/common/utils/validate.js'
	export default {
		data() {
			return {
				pickerDiy1656986153485: false,
				mobile: "",
				security_code: "",
				password: "",
				password_code: "",
				address: "",
				isShow: true,
				userInfo: {},
				is_submit: false,
				area: [],
			}
		},
		onLoad() {
			
		},
		onShow() {
			this.getUserInfo();
		},
		methods: {
			// 获取用户资料  postUserInfo
			getUserInfo() {
				this.$api.post(global.apiUrls.glyUser, {
					
				}).then(res => {
					// console.log(res);
					this.isShow = false;
					if (res.data.code == 200) {
						this.userInfo = res.data.data;
						this.address = res.data.data.areaProvinces + res.data.data.areaCity + res.data.data.areaRegion;
						this.area = res.data.data.area;
					} else {
						this.$message.info(res.data.message);
					}
				})
			},
			areaChange(e) {
				this.address = e.result;
				this.area = e.value;
			},
			// 修改地址  gylChangeAddress
			saveInfo() {
				if (this.is_submit) return;
				if (!this.userInfo.consignee) {
					this.$message.info('请输入收货人');
					return false;
				}
				if (!validate(this.userInfo.tel, 'require')) {
					this.$message.info('请输入手机号');
					return false;
				}
				if (!validate(this.userInfo.tel, 'phone')) {
					this.$message.info('请输入正确的手机号');
					return false;
				}
				if (!this.address) {
					this.$message.info('请选择所在地区');
					return false;
				}
				if (!this.userInfo.receiving_address) {
					this.$message.info('请输入详细地址');
					return false;
				}
				this.is_submit = true;
				this.$api.post(global.apiUrls.gylChangeAddress, {
					area: JSON.stringify(this.area),
					consignee: this.userInfo.consignee,
					tel: this.userInfo.tel,
					receiving_address: this.userInfo.address
				}).then(res => {
					this.$message.info(res.data.message);
					if (res.data.code == 200) {
						setTimeout(() => {
							uni.navigateBack();
						}, 800)
					} else {
						this.is_submit = false;
					}
				}).catch(err => {
					this.is_submit = false;
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.page {
		background: url(https://www.shiyaocanyin.com/images/8.png) no-repeat #f5f5f5;
		background-size: 100% auto !important;
		.bar_info {
			width: 750rpx;
			height: 88rpx;
			overflow: hidden;
			z-index: 10;
			position: fixed;
			top: 0rpx;
		
			.title_bar {
				padding: 0 32rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
		
				.title_bar_left {
					width: 50rpx;
					.title_bar_left_icon {
						width: 18rpx;
						height: 32rpx;
					}
				}
		
				.title_bar_center {
					line-height: 88rpx;
					font-size: 36rpx;
					font-weight: 400;
				}
		
				.title_bar_right {
					width: 50rpx;
				}
			}
		}
		.set_content {
			padding: 32rpx 20rpx;
			.set_list {
				background: #fff;
				border-radius: 20rpx;
				padding: 0 32rpx;
				margin-bottom: 24rpx;
				.list_item {
					display: flex;
					align-items: center;
					justify-content: space-between;
					padding: 40rpx 0;
					border-bottom: 1rpx solid #eee;
					.list_item_left {
						font-size: 30rpx;
						width: 140rpx;
						color: #222;
					}
					.list_item_right {
						width: calc(100% - 140rpx);
						font-size: 26rpx;
						text-align: right;
						// pointer-events: none;
					}
					.select_icon {
						width: 24rpx;
						height: 24rpx;
					}
				}
				.no_border {
					border-bottom: 1rpx solid transparent;
				}
			}
		}
	}
	.btn_info {
		width: 100%;
		position: fixed;
		bottom: 0;
		padding: 15rpx 25rpx;
		z-index: 10;
		.del_btn {
			width: 700rpx;
			height: 80rpx;
			background: #EFEFEF;
			border-radius: 50rpx;
			font-size: 30rpx;
			font-weight: 500;
			color: #41AF36;
			text-align: center;
			line-height: 80rpx;
			border: 2rpx solid #41AF36;
		}
		.save_btn {
			width: 700rpx;
			height: 80rpx;
			background: #41AF36;
			border-radius: 50rpx;
			font-size: 30rpx;
			font-weight: 500;
			color: #fff;
			text-align: center;
			line-height: 80rpx;
			margin-top: 30rpx;
		}
	}
	
	.codeLogin_fd1_1_c2 {
		font-size: 26rpx;
		color: #41AF36;
		font-weight: 500;
		margin-left: 30rpx;
	}
	
	.myInfo_picker2_0_c2 {
		color: #41AF36;
		line-height: 40rpx;
		font-size: 32rpx;
		font-weight: 400;
	}
	
	.myInfo_picker2_0_c1 {
		font-size: 32rpx;
		font-weight: 500;
		color: #333333;
	}
	
	.myInfo_picker2_0_c0 {
		line-height: 40rpx;
		font-size: 32rpx;
		font-weight: 400;
		color: #BFBFBF;
	}
	
	.myInfo_picker2_0 {
		border-bottom: 1px solid #eee;
		background: #fff;
		padding: 0rpx 32rpx 0rpx 32rpx;
		line-height: 88rpx;
		border-radius: 25rpx 25rpx 0rpx 0rpx;
		background-size: 100% auto !important;
	}
</style>